package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckItem;
import com.itheima.pojo.Map;
import com.itheima.service.MapService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/map")
public class MapController {

    @Reference
    private MapService mapService;

    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = mapService.pageQuery(queryPageBean);
        return pageResult;
    }

    @RequestMapping("/delete")
    public Result delete(Integer id){
        try{
            mapService.deleteById(id);
        }catch (Exception e){
            e.printStackTrace();
            //服务调用失败
            return new Result(false, MessageConstant.DELETE_ADDRESS_FAIL);
        }
        return  new Result(true, MessageConstant.DELETE_ADDRESS_SUCCESS);
    }

    @RequestMapping("/add")
    public Result add(@RequestBody Map map){
        try{
            mapService.add(map);
        }catch (Exception e){
            e.printStackTrace();
            //服务调用失败
            return new Result(false, MessageConstant.ADD_ADDRESS_FAIL);
        }
        return  new Result(true, MessageConstant.ADD_ADDRESS_SUCCESS);
    }

    @RequestMapping("/findAll")
    public Result findAll(){
        try{
            List<Map> list = mapService.findAll();
            return  new Result(true, MessageConstant.QUERY_ADDRESS_SUCCESS,list);
        }catch (Exception e){
            e.printStackTrace();
            //服务调用失败
            return new Result(false, MessageConstant.QUERY_ADDRESS_FAIL);
        }
    }
}
